## Time-stamp: <2007-07-11 10:21:39 ejoearm> 
 

## ecall Str      -- is called each time something is received on a socket
## sendSocket Str -- is called to return values to the socket

package require Iwidgets 4.0

## This is needed
puti "loading wish.tcl -- yes"

# fconfigure stdout -encoding binary

global chk

proc erlTagEvent { win tag type w x y } {
    set alltags [$w gettags current]
    sendSocket "event $win tagEvent $tag $type { $alltags } $x $y\377"
}

proc windowMoved { x y w h w} {
    sendSocket "$win winMoved $x $y $w $h\377"
}


proc windowDestroyed { win } {
    sendSocket "$win winDestroyed\377"
}
			    

proc erlevent { win args } {
    sendSocket "event $win $args\377"
}

proc erlevent1 { win str args} {
    sendSocket "event $win $str $args\377"
}


proc crInEntry { id w } {
    set val [$w get]
    sendSocket stdout "click $id $val\377"
}

proc click { id } {
    sendSocket stdout "click $id\377"
}


proc clickCB { id w } { 
    global chk
    set var [$w cget -variable]
    set ret [set $var]
}

proc readCheck { widget } {
    global chk
    set var [$widget cget -variable]
    set ret [set $var]
    return $ret
}

proc setCheck { widget val} {
    global chk
    set var [$widget cget -variable]
    set $var $val
}



proc werr { w text } {
    foreach item [winfo children $w] {
	destroy $item
    }
    label $w.e -bitmap warning
    label $w.l -bd 1 -text $text
    button $w.ok -text "Confirm" -command "destroy $w" 
    pack $w.e $w.l
    pack $w.ok
}

proc ecall { cmd } {
    global x
    ## cmds received here
    ## mk_window      -> call mk_window
    ## mk_button P K  -> call mk_button P K
    ## mk_obj P O     -> call mk_obj P O
    ## Other          -> call eval Other

    set n [lindex $cmd 0]
    set cmd1 [lrange $cmd 1 end] 
    ## puti "$cmd1"
    puts stderr "debug ecall:: $cmd1"
    set ret [catch $cmd1 val]
    puts stderr "ecall Cmd = $cmd"
    set ret [catch $cmd1 val]
    update
    if { $ret == 0} {
	sendSocket "eret  $n $val\377"
    } else {
	sendSocket "error $n $cmd $val\377"
    }
}

proc ecast { cmd } {
    global x
    set n [lindex $cmd 0]
    set cmd1 [lrange $cmd 1 end] 
    ## puts stderr "ecast Cmd = $cmd"
    ## puti "$cmd1"
    ## puts stderr "debug ecast:: cmd = |$cmd|"
    ## puts stderr "debug ecast:: cmd1 = |$cmd1|"
    set ret [catch $cmd1 val]
    update
    ## puti "ret = $val"
    if { $ret != 0} {
	sendSocket "notify $n $cmd $val\377"
    }
}

global max
set max 100

#lappend auto_path /home/joe/installed/graphics/BWidget-1.4.1
#package require BWidget

## proc puti {str} {
##     .tx.text insert end $str\n"
## }
## 
## frame .tx
## text .tx.text -yscrollcommand ".tx.scroll set"
## scrollbar .tx.scroll -command ".tx.text yview"
## pack .tx.scroll -side right -fill y
## pack .tx.text -side left
## pack .tx -side top
## 
## source rnotebook.tcl
## 
## option add *highlightThickness 0
## tk_setPalette gray60
## 
## proc mk_notebook {n} {
##     Rnotebook:create $n  -borderwidth 2
##     pack $n -fill both -expand 1 -padx 10 -pady 10
##     destroy [winfo children $n.tabs]
## }
## 
## proc add_notebook_page {n index str} {
##     Rnotebook:addtab $n $index
##     [Rnotebook:button $n $index] config -text $str
##     set f [Rnotebook:frame $n $index]
##     Rnotebook:raise $n $index
##     return $f
## }
## 
## # returns the inner frame
## 
## proc mk_labelframe { n str} {
##     LabelFrame:create $n -text $str
## }
## 
## # load all the extension libraries

#source lib_ScrollEditor.tcl
#source lib_Image.tcl
#source lib_LabelFrame.tcl
#source lib_ComboBox.tcl
#source lib_NoteBook.tcl

# puts stderr "wish loaded"

# font create txtFont -family Fixed -size 14 -weight bold

#image create photo cross -file GCrossX_a.GIF
#image create photo down -file Down_s.GIF

#package require Img






